
<template>
  <div>
    <SearchForm
        @search="onSearch"
        @reset="onReset"
        :search-list="searchList" :search-params="searchParams">
    </SearchForm>

    <div class="table-layout">
      <el-card shadow="never">
        <div class="table-box">
          <el-table
              size="large"
              stripe
              border
              v-loading="loading"
              max-height="500px"
              :data="tableData"
              row-key="id"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(255, 255, 255, 0.8)"
              @selection-change="onSelect"
          >
            <el-table-column prop="course_name" label="课程名称"/>
            <el-table-column prop="course_schedule" label="上课时间"/>
            <el-table-column prop="student.name" label="学生"/>
            <el-table-column prop="grade" label="年级"/>
            <el-table-column prop="class_name" label="班级"/>
            <el-table-column prop="teacher_name" label="上课老师"/>
            <el-table-column prop="location" label="上课地点"/>
            <el-table-column label="预约状态" width="100px">
              <template slot-scope="scope">
                <el-tag type="success" v-if="scope.row.status === 1">已预约</el-tag>
                <el-tag type="danger" v-else>取消</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="100px">
              <template slot-scope="scope">
                <el-button v-if="scope.row.status === 1" type="text" style="color: #F82222" @click="onCancel(scope.row)">取消</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-card>
      <div class="page-box">
        <el-pagination
            background
            :current-page="pageNo"
            :page-sizes="pageSizes"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalSize"
            @size-change="changePageSize"
            @current-change="changePageNo"
        />
      </div>
    </div>
    <Add ref="addFormRef" @get-page="initData" />
  </div>
</template>
<script>

import crud from "@/mixins/crud";
import { http } from "@/api";
import Add from "./add";
import {handleTree} from "@/utils/tree";
export default {
  name: "index",
  components: {
    Add
  },
  mixins: [crud],
  data() {
    return {
      request: http.courseRecord,
      searchList: [
        {
          label: '课程',
          prop: 'course_id',
          name: 'select',
          options: [],
          clearable: true
        },
      ],
      searchParams: {
        course_id: '',
      },
      defaultParams: {
      },
      tableData: [

      ]
    }
  },
  created() {
    http.course.list().then(res => {
      this.searchList[0].options = res.data.map(item => {
        return {
          value: item.id,
          label: item.name
        }
      })
    })
  },
  methods: {
    onCancel(row) {
      // 对话框
      this.$confirm('确认取消？', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
          .then(() => {
            http.courseRecord.cancel(row.id).then(res => {
              this.$message.success('取消成功')
              this.onSearch()
            })
          })
          .catch(() => {

          })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
